package com.zyh.day02

object ListTest {
  def main(args: Array[String]): Unit = {
    val list: List[Int] = List(1, 2, 3)
    var list2:Nil.type = Nil

    val i1: Int = list.head
    val i2: Int = list(1)
    val i3: Int = list(2)
    println(s"i1,i2,i3 = ${i1}$i2$i3")

    //根据下标更新返回新的集合
    val list3: List[Int] = list.updated(0, 2)
    println(s"list = ${list}")
    println(s"list3 = ${list3}")
    //删除
    val list4: List[Int] = list.drop(2)
    println(s"list = ${list}")
    println(s"list4 = ${list4}")
    //添加
    val list5:List[Int] = list:+4
    println(s"list = ${list}")
    println(s"list5 = ${list5}")

    val list6:List[Int] = 0 +: list5
    println(s"list5 = ${list5}")
    println(s"list6 = ${list6}")

    val list7:List[Int] = -1 :: list6
    println(s"list7 = ${list7}")

    val list8: List[Any] = list ::: list7
    println(s"list8 = ${list8}")

    var j =0
    while(j<list8.size){
      print(list8(j)+" ")
      j+=1
    }
    println()
    for(item <- list8) print(item+" ")
  }
}
